package com.bwie.es.service.impl;

import com.bwie.es.domain.EsShop;
import com.bwie.es.domain.request.EsShopRequest;
import com.bwie.es.mapper.EsMapper;
import com.bwie.es.service.EsService;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Es业务处理层
 *
 * @author <a href="mailto:2891704036@qq.com">zhiyuheng</a>
 * @version 1.0
 * @description: Es业务处理层
 * @date 2025/9/9 10:27
 */
@Service
public class EsServiceImpl implements EsService {

    @Autowired
    private EsMapper esMapper;

    /**
     * 创建索引
     */
    @Override
    public void createIndex() {
        esMapper.createIndex();
    }

    /**
     * 添加
     * @param esShop
     */
    @Override
    public void add(EsShop esShop) {
        esMapper.insert(esShop);
    }

    /**
     * 修改
     * @param esShop
     */
    @Override
    public void update(EsShop esShop) {
        esMapper.updateById(esShop);
    }

    /**
     * 禁用
     */
    @Override
    public void delete(Long id) {
        esMapper.deleteById(id);
    }

    /**
     * 店铺列表
     * @param request
     * @return
     */
    @Override
    public EsPageInfo<EsShop> pageList(EsShopRequest request) {
        LambdaEsQueryWrapper<EsShop> wrapper = new LambdaEsQueryWrapper<>();
        EsShop esShop = new EsShop();
        if (request.getShopName() != null && request.getShopName() != ""){
            wrapper.match(esShop.getShopName() , request.getShopName());
        }
        EsPageInfo<EsShop> pageInfo = esMapper.pageQuery(wrapper, request.getPageNum(), request.getPageSize());
        return pageInfo;
    }
}
